package com.aptech.fpt.c0810g.newspj.dataaccess;

import com.aptech.fpt.c0810g.newspj.dataaccess.share.InvokeSelectQuery;
import com.aptech.fpt.c0810g.newspj.entity.Source;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author zang
 */
public class SourceAction {

    /**
     * @return Tra ve danh sach cac trang muon lay tin
     */
    public ArrayList<Source> getSourceList() {
        ArrayList<Source> list = new ArrayList<Source>();
        //Cac cot muon truy van
        ArrayList<String> colums = new ArrayList<String>();
        colums.add("ID");
        colums.add("Name");
        colums.add("HomePage");
        colums.add("Logo");
        //Cac dieu dien 
        ArrayList<String> codition = new ArrayList<String>();
        //Bang muon truy van
        String tableName = "Source";
        ArrayList<HashMap<String, Object>> records = new InvokeSelectQuery().getList(colums, tableName, codition);
        //add gia tri
        for (int i = 0; i < records.size(); i++) {
          Source sourceObj = new Source();
          sourceObj.setId(Integer.valueOf(records.get(i).get("ID").toString()));
          sourceObj.setName(records.get(i).get("Name").toString());
          sourceObj.setHomePage(records.get(i).get("HomePage").toString());
          sourceObj.setPhoto(records.get(i).get("Logo").toString());
          
          list.add(sourceObj);
        }
        return list;
    }
}
